"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Hall_1 = __importDefault(require("../models/Hall"));
const Room_1 = __importDefault(require("../models/Room"));
async function default_1(call) {
    const { roomId, player } = call.req;
    let conn = Hall_1.default.instance.get(player.openid);
    if (!conn) {
        conn = Hall_1.default.instance.connect(player.openid, call.conn);
        // call.error("加入失败，已断开连接")
        // return
    }
    if (!Room_1.default.instance.canJoin(roomId)) {
        call.error("加入失败，房间已满员");
        return;
    }
    const room = Room_1.default.instance.join(roomId, player);
    if (!room) {
        call.error("加入失败，房间不存在");
        return;
    }
    call.succ({ room });
}
exports.default = default_1;
